package com.css.fxfzcpxx.modules.logRecord.controller;

import com.css.fxfzcpxx.base.response.RestResponse;
import com.css.fxfzcpxx.modules.logRecord.entity.SysLog;
import com.css.fxfzcpxx.modules.logRecord.service.LogRecordService;
import com.css.fxfzcpxx.modules.logRecord.vo.SysLogVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 徐治宇
 * @CreateTime: 2023/09/11
 * @Description: 日志记录
 */
@Slf4j
@RestController
@RequestMapping("/logRecord")
public class LogRecordController {
    @Autowired
    LogRecordService logRecordService;



    /**
     * 日志保存
     * @return
     */
    @PostMapping("/save")
    public RestResponse save(HttpServletRequest request, @RequestBody SysLogVo sysLog){
        RestResponse restResponse = null;
        try {
            logRecordService.save(sysLog,request);
            restResponse = RestResponse.succeed("保存成功");
        } catch (Exception e) {
            String errorMessage = "保存失败!";
            log.error(errorMessage, e);
            restResponse = RestResponse.fail(errorMessage);
        }
        return restResponse;
    }


}
